<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Logo = {
      template:`
        <h3>
          我是子组件 
          <button @click="emit">向父组件发送数据</button>
        </h3>
      `,
      data(){
        return {
          msg: '子组件中的数据'
        }
      },
      methods: {
        emit(){
          // $emit('自定义事件名', 携带参数) 触发 组件 一个自定义的事件
          this.$emit('biubiubiu', this.msg)
        }
      },
      mounted(){
        console.log(this);
      }
    }
    const CommonHead = {
      /* 
      定义组件的 结构 
      */
      template:`
        <div>
          <h1>我是父组件</h1>
          {{ msg }}
          <logo @biubiubiu="fn"></logo>
        </div>
      `,
      data(){
        return {
          msg: '我是父组件动态数据'
        }
      },
      methods: {
        fn(msg){
          console.log(msg);
          this.msg = msg;
        }
      },
      components: {
        Logo: Logo
      }
    }
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>